package com.wubai.subject.domain.handler.subject;

import com.wubai.subject.common.enums.IsDeletedFlagEnum;
import com.wubai.subject.common.enums.SubjectInfoTypeEnum;
import com.wubai.subject.domain.convert.SubjectBriefConverter;
import com.wubai.subject.domain.convert.SubjectRadioConverter;
import com.wubai.subject.domain.entity.SubjectInfoBO;
import com.wubai.subject.domain.entity.SubjectOptionBO;
import com.wubai.subject.infra.basic.entity.SubjectBrief;
import com.wubai.subject.infra.basic.entity.SubjectRadio;
import com.wubai.subject.infra.basic.service.SubjectBriefService;
import com.wubai.subject.infra.basic.service.SubjectRadioService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class BriefTyperHandler implements SubjectTypeHandler{


    @Resource
    private SubjectBriefService subjectBriefService;



    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {

        List<SubjectBrief> subjectBriefList = SubjectBriefConverter.INSTANCE.convertBOToBriefList(subjectInfoBO.getOptionList());

        subjectBriefList.forEach(subjectBrief->{

            subjectBrief.setSubjectId(subjectInfoBO.getId());
            subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());

        });
        subjectBriefService.batchInsert(subjectBriefList);



    }

    @Override
    public SubjectOptionBO query(int subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(Long.valueOf(subjectId));
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
